package vip.xumy.admin.sys.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import vip.xumy.admin.sys.pojo.ActionLog;

/**
 * @author:mengyxu
 * @date:2020年2月13日
 */

@Mapper
public interface IActionLogMapper {

	static final String BASE_COLUMN = "id, type, module, user_id, login_ip, time, context";

	@Select({ "<script>", "SELECT * FROM sys_action_log ", "<where>",
			"<if test='type != null'> AND type = #{type} </if>",
			"<if test='module != null'> AND module = #{module} </if>",
			"<if test='userId != null'> AND user_id like CONCAT('%',#{userId},'%') </if>",
			"<if test='context != null'> AND context like CONCAT('%',#{context},'%') </if>",
			"<if test='startTime != null'> AND time >= #{startTime} </if>",
			"<if test='endTime != null'> AND #{endTime} > time </if>", "</where>", "ORDER BY time DESC", "</script>" })
	List<ActionLog> queryByExample(ActionLog example);

	@Insert({ "INSERT INTO BusinessLog ( ", BASE_COLUMN, " ) VALUES ",
			"(#{id}, {type}, #{module}, #{userId}, #{loginIp}, #{time}, #{context})" })
	void insert(ActionLog log);

	@Insert({ "<script>", "INSERT INTO BusinessLog ( ", BASE_COLUMN, " ) VALUES ",
			"<foreach collection='list' item='log' separator=','>",
			"(#{log.id}, {log.type}, #{log.module}, #{log.userId}, #{log.loginIp}, #{log.time}, #{log.context}) ",
			"</foreach>", "</script>" })
	void insertBatch(List<ActionLog> logs);

}
